package com.cloudptt.api.product.config.sys;

import com.mcptt.db.model.UserInfo;

public class LoginUserInfo 
{
	public final static long PRIVILEGE_MASK = 0xffffffff;
	private final static long RECORD_PRIV = 0x1;
	private final static long LOCATION_PRIV = 0x2;
	private final static long VIDEO_PRIV = 0x4;
	private final static long MESSAGE_PRIV = 0x8;
	
	private String num = null;
	private String pwd = null;
	private String name = null;
	private String userKey = null;
	private long privilege = PRIVILEGE_MASK;
	
	public LoginUserInfo(String num,String pwd)
	{
		this.num = num;
		this.pwd = pwd;
	}
	public LoginUserInfo(String num,String pwd,String name,String userKey)
	{
		this.num = num;
		this.pwd = pwd;
		this.name = name;
		this.userKey = userKey;
	}
	
	public boolean isSameOne(String num,String pwd)
	{
		if(this.num.equals(num)
				&& this.pwd.equals(pwd))
		{
			return true;
		}
		return false;
	}
	public boolean isSameNum(String num)
	{
		if(this.num.equals(num))
		{
			return true;
		}
		return false;
	}
	
	public boolean isInvalidUser()
	{
		if(this.num == null
				|| this.num.length() <= 0
				|| this.userKey == null
				|| this.userKey.length() <= 0)
		{
			return true;
		}
		return false;
	}
	
	public boolean isSameIMEI(String imei)
	{
		if(this.userKey != null
				&& this.userKey.equals(imei))
		{
			return true;
		}
		return false;
	}
	
	/* add by xu for 支持IMSI登录@20170731 */
	public boolean isSameIMSI(String imsi)
	{
		if(this.userKey != null
				&& this.userKey.equals(imsi))
		{
			return true;
		}
		return false;
	}
	
	public String getNum() {
		return num;
	}

	protected void setNum(String num) {
		this.num = num;
	}

	public String getPwd() {
		return pwd;
	}

	protected void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public String getName() {
		return name;
	}

	protected void setName(String name) {
		this.name = name;
	}

	public String getUserKey() {
		return userKey;
	}

	protected void setUserKey(String userKey) {
		this.userKey = userKey;
	}

	public long getPrivilege( ) {
		return privilege;
	}
	public void setPrivilege( long privilege ) {
		this.privilege = privilege;
	}
	
	public boolean isRecordGranted(){
		return (this.privilege & RECORD_PRIV ) != 0;
	}
	
	public boolean isLocationGranted(){
		return (this.privilege & LOCATION_PRIV ) != 0;
	}
	
	public boolean isVideoGranted(){
		return (this.privilege & VIDEO_PRIV ) != 0;
	}
	
	public boolean isMessageGranted(){
		return (this.privilege & MESSAGE_PRIV ) != 0;
	}
	
	public String toString()
	{
		StringBuffer strBuff = new StringBuffer("VersionInfo:");
		strBuff.append("num = ").append(num).append(",");
		strBuff.append("name = ").append(name).append(",");
		strBuff.append("userKey = ").append(userKey).append(",");
		strBuff.append("privilege = ").append(Long.toHexString(privilege) ).append(";");

		return strBuff.toString();
	}
}
